import requests
import json

# 基础 URL
completion_url = "http://106.55.8.90:7001/api/syncCompletion/syncCompletion/invoke?coocaaVId={}"

# categroys 1:电视剧 4:电影 5 综艺
url = "http://mgr.media.tc.skysrt.com/api/ownMediaResManage/pageList.html?categorys=5&businessType=0&status=1&offVideo=1&contentForm=0&order=desc&isDoubanType=0&page=2&rows=500&filterSourceType=0&coocaaValid=coocaa"

payload = {}
headers = {
    'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
}

response = requests.request("GET", url, headers=headers, data=payload)

# 1. 先解析响应内容为JSON
response_data = response.json()  # 这将把响应内容解析为Python字典

# 2. 从解析后的数据中获取信息
total = response_data.get("total")  # 使用get方法避免键不存在时报错
row_str = response_data.get("rows", [])  # 获取rows列表，如果不存在则默认为空列表
movies = json.loads(row_str)  # 解析字符串为字典

# 3. 提取每个影片的 coocaaVId
for movie in movies:
    coocaa_vid = movie.get("coocaaVId")  # 使用 get 方法避免键不存在时报错
    title = movie.get("title", "无标题")  # 同时获取标题（可选）
    print(f"影片标题: {title}, coocaaVId: {coocaa_vid}")
    url = completion_url.format(coocaa_vid)
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()  # 如果响应状态码不是 200，抛出异常
        print(f"Response for {coocaa_vid}: {response.text}")
    except requests.exceptions.RequestException as e:
        print(f"Error occurred for {coocaa_vid}: {e}")
